//
//  FANSearchView.swift
//  Weibo - Swift
//
//  Created by user on 16/4/16.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit

class FANSearchView: UIView {

    @IBOutlet weak var RightCons: NSLayoutConstraint!
    
    @IBOutlet weak var textField: UITextField!
    
    private lazy var leftView:UIImageView = {
       
        let imageView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        
        imageView.contentMode = .Center
        
        return imageView
    }()
    
    class func loadSearchView()->FANSearchView {
        
       return NSBundle.mainBundle().loadNibNamed("FANSearchView", owner: nil, options: nil).last as! FANSearchView
        
    }
    
    override func awakeFromNib() {
        
        leftView.frame.size = CGSize(width: self.frame.size.height/2, height: self.frame.size.height/2)

        textField.leftView = leftView
        
        textField.leftViewMode = .Always
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        super.init(coder: aDecoder)
    }
    
    
    @IBAction func didCancelClick(sender: UIButton) {
        
        self.RightCons.constant = 0
        
        UIView.animateWithDuration(0.25) { () -> Void in
            
            self.layoutIfNeeded()
        }
        
        self.textField.resignFirstResponder()
        
    }
    
    @IBAction func editingBeginClick(sender: UITextField) {
        
        self.RightCons.constant = 45
        
        UIView.animateWithDuration(0.25) { () -> Void in
            
            self.layoutIfNeeded()
        }
    }
    

}
